package cn.edu.neu.lab603.cloudeval.strategy.policy

import java.util.concurrent.atomic.AtomicLong

import cn.edu.neu.lab603.cloudeval.entity.DataCenter

/** 实现静态阈值构建的迁移时机策略。
  *
  * @author yfwz100
  */
class ReAllocationTimePolicyStaticThreshold(val threshold: Double,
                                            val checkPeriod: Int = 25) extends ReAllocationTimePolicy {

  import MigrationDef._

  // 时钟周期计数器
  val clockCounter = new AtomicLong

  override def isTimeForReallocation(implicit dataCenter: DataCenter): Boolean = {
    if (clockCounter.incrementAndGet() % checkPeriod == 0)
      dataCenter.pmList.exists { host =>
        host.getUsedResPct("mips") >= threshold || host.isIdle
      }
    else
      false
  }

  override def toString = "Thr"
}
